﻿Public Class DRUGCAUTION
    Dim connect As CONDB = CONDB.NewConnection()
    Dim PROVIDER_Check As New PROVIDERSCLASS

    Private Sub selectSlabelToGrid()
        Dim dt As DataTable
        Dim objSelectSlabel As New DRUGCAUTIONCLASS
        dt = connect.GetTable(objSelectSlabel.selectMasslabel_)
        sgvMasslabel.PrimaryGrid.DataSource = dt
    End Sub

    Private Sub clearForm()
        txtSLID.Clear()
        txtSLABELNAME_TH.Clear()
        txtSLABELNAME_EN.Clear()
        ckbMasslabelStatus.Checked = False
    End Sub

    Private Sub DRUGCAUTION_Load(sender As Object, e As EventArgs) Handles MyBase.Load
        DesignForm(Me)
        DesignGrid(sgvMasslabel)

        selectSlabelToGrid()

        PROVIDER_Check.GETHOSEM(CInt(main.txtUserRequest.Text.Trim), Convert.ToString(Me.Tag))
    End Sub

    Private Sub sgvMasslabel_CellClick(sender As Object, e As DevComponents.DotNetBar.SuperGrid.GridCellClickEventArgs) Handles sgvMasslabel.CellClick
        Dim grid As DevComponents.DotNetBar.SuperGrid.GridRow
        grid = e.GridPanel.ActiveRow

        If CType(e.GridPanel.ActiveRow, DevComponents.DotNetBar.SuperGrid.GridRow).Cells("รหัสฉลากเตือน").Value() IsNot DBNull.Value Then
            txtSLID.Text = CType(e.GridPanel.ActiveRow, DevComponents.DotNetBar.SuperGrid.GridRow).Cells("รหัสฉลากเตือน").Value()
        Else
            txtSLID.Clear()
        End If

        If CType(e.GridPanel.ActiveRow, DevComponents.DotNetBar.SuperGrid.GridRow).Cells("ฉลากเตือนไทย").Value() IsNot DBNull.Value Then
            txtSLABELNAME_TH.Text = CType(e.GridPanel.ActiveRow, DevComponents.DotNetBar.SuperGrid.GridRow).Cells("ฉลากเตือนไทย").Value()
        Else
            txtSLABELNAME_TH.Clear()
        End If

        If CType(e.GridPanel.ActiveRow, DevComponents.DotNetBar.SuperGrid.GridRow).Cells("ฉลากเตือนอังกฤษ").Value() IsNot DBNull.Value Then
            txtSLABELNAME_EN.Text = CType(e.GridPanel.ActiveRow, DevComponents.DotNetBar.SuperGrid.GridRow).Cells("ฉลากเตือนอังกฤษ").Value()
        Else
            txtSLABELNAME_EN.Clear()
        End If

        If CType(e.GridPanel.ActiveRow, DevComponents.DotNetBar.SuperGrid.GridRow).Cells("สถานะการเปิดใช้งาน").Value() = True Then
            ckbMasslabelStatus.Checked = True
        Else
            ckbMasslabelStatus.Checked = False
        End If

        btnAddMasslabel.Enabled = False
    End Sub

    Private Sub btnAddMasslabel_Click(sender As Object, e As EventArgs) Handles btnAddMasslabel.Click
        If main.PROVIDERPOLICIES.checklogin_user_ = True Then
            If PROVIDER_Check.PADD_ = True Then
                If txtSLABELNAME_TH.Text.Length.ToString > 0 Then
                    Dim objInsertMasslabel As New DRUGCAUTIONCLASS
                    objInsertMasslabel.SLABELNAME_TH_ = txtSLABELNAME_TH.Text.Trim
                    objInsertMasslabel.SLABELNAME_EN_ = txtSLABELNAME_EN.Text.Trim
                    objInsertMasslabel.STATUS_ = ckbMasslabelStatus.Checked

                    If objInsertMasslabel.insertMasslabel = True Then
                        MsgBox("เพิ่มฉลากเตือนเรียบร้อยแล้ว")
                        clearForm()
                        selectSlabelToGrid()
                    End If
                Else
                    MsgBox("โปรดระบุข้อมูลให้ครบถ้วน")
                End If
            Else
                MsgBox(PROVIDER_Check.PADDMSG_)
            End If
        Else
            TOASTCLASS.gloadToastMSG(Me, main.PROVIDERPOLICIES.LOGINUSERMSG_)
            main.txtUserRequest.Focus()
        End If
    End Sub

    Private Sub btnEditMasslabel_Click(sender As Object, e As EventArgs) Handles btnEditMasslabel.Click
        If main.PROVIDERPOLICIES.checklogin_user_ = True Then
            If PROVIDER_Check.PUPD_ = True Then
                If txtSLABELNAME_TH.Text.Length.ToString > 0 And txtSLID.Text.Length.ToString > 0 Then
                    Dim objEditMasslabel As New DRUGCAUTIONCLASS
                    objEditMasslabel.SLID_ = txtSLID.Text
                    objEditMasslabel.SLABELNAME_TH_ = txtSLABELNAME_TH.Text.Trim
                    objEditMasslabel.SLABELNAME_EN_ = txtSLABELNAME_EN.Text.Trim
                    objEditMasslabel.STATUS_ = ckbMasslabelStatus.Checked

                    If objEditMasslabel.editMasslabel = True Then
                        MsgBox("แก้ไขฉลากเตือนเรียบร้อยแล้ว")
                        clearForm()
                        selectSlabelToGrid()
                        btnAddMasslabel.Enabled = True
                    End If
                Else
                    MsgBox("โปรดระบุข้อมูลให้ครบถ้วน")
                End If
            Else
                MsgBox(PROVIDER_Check.PUPDMSG_)
            End If
        Else
            TOASTCLASS.gloadToastMSG(Me, main.PROVIDERPOLICIES.LOGINUSERMSG_)
            main.txtUserRequest.Focus()
        End If
    End Sub
End Class